package com.hxkcloud.nurse.activitys;

import android.content.Intent;
import android.content.res.Resources;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.os.Message;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.PopupWindow;
import android.widget.TextView;

import com.hxkcloud.nurse.R;
import com.hxkcloud.nurse.YjhApplication;
import com.hxkcloud.nurse.adapter.AllReportApater;
import com.hxkcloud.nurse.adapter.ReportDetailListAdapter;
import com.hxkcloud.nurse.beans.DpatientInfoBean;
import com.hxkcloud.nurse.beans.MyReportValueBean;
import com.hxkcloud.nurse.beans.ReportValueBean;
import com.hxkcloud.nurse.beans.resultbeans.ObjectResultBean;
import com.hxkcloud.nurse.popup.CalendarPopWindow;
import com.hxkcloud.nurse.request.MessageCode;
import com.hxkcloud.nurse.request.YiJiaHuNetWorkUtils;
import com.hxkcloud.nurse.utils.Utils;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;

import lecho.lib.hellocharts.gesture.ZoomType;
import lecho.lib.hellocharts.model.Axis;
import lecho.lib.hellocharts.model.AxisValue;
import lecho.lib.hellocharts.model.Line;
import lecho.lib.hellocharts.model.LineChartData;
import lecho.lib.hellocharts.model.PointValue;
import lecho.lib.hellocharts.model.Viewport;
import lecho.lib.hellocharts.view.LineChartView;

/**
 * ProjectName: YJHCuzhong
 * PackageName: com.yjhcloud.stroke.activitys
 * Description:我的检查报告详情
 * Create by Ray.
 * Date: 2016/10/8 18:46
 */
public class MyReportDetailActivity extends BaseActivity implements View.OnClickListener, ReportDetailListAdapter.PostOptionsListener {

    private LinearLayout ll_title;
    private ImageView iv_back;
    private TextView tv_title;
    private TextView tv_input;

    private TextView startTV;//开始日期
    private TextView endTV;//结束日期
    private TextView allTV;//全部
    private TextView referenceTV;//参考值

    private CalendarPopWindow calendarView;
    private LineChartView chart;
    private LineChartData data;

    private RecyclerView recyclerView;
    private ReportDetailListAdapter adapter;
    private List<ReportValueBean> reportValueBeans;

    private ObjectResultBean<MyReportValueBean> resultBean;

    private boolean isStartDate = false;
    private boolean isEndDate = false;

    private String startDateStr = "";
    private String endDateStr = "";

    private String reportId = "";//报告Id
    private String reportName = "";//报告名

    private int betweenDays = 7;

    float max = 0;
    float min = 0;

    private boolean isDoctor = false;

    private PopupWindow allPopup;
    private ListView allListView;
    private AllReportApater allAdapter;
    private View allWholeView;
    private List<DpatientInfoBean> reportLists;

    private String patientId;

    private boolean isTitleClick = false;

    private TextView dataUnitTV;

    private String unit="";


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_layout_myreportdetail);
        reportValueBeans = new ArrayList<>();

        if (getIntent().hasExtra("reportId")) {
            reportId = getIntent().getStringExtra("reportId");
        }
        if (getIntent().hasExtra("reportName")) {
            reportName = getIntent().getStringExtra("reportName");
        }
        if (getIntent().hasExtra("isDoctor")) {
            isDoctor = getIntent().getBooleanExtra("isDoctor", false);
        }
        if (getIntent().hasExtra("reportList")) {
            reportLists = (List<DpatientInfoBean>) getIntent().getSerializableExtra("reportList");
        }
        if (getIntent().hasExtra("patientid")) {
            patientId = getIntent().getStringExtra("patientid");
        }
        if (loginInfo.getUserStyle().equals(YjhApplication.userstyle_patient)) {
            patientId = loginInfo.getPatientId();
        }
        if (reportLists == null) {
            reportLists = new ArrayList<>();
        }
        initView();
//        initData();
        initListener();


    }

    private void initAllPopup() {
        allPopup = new PopupWindow(this);
        View allView = LayoutInflater.from(this).inflate(R.layout.popup_layout_kind, null);
        allPopup.setContentView(allView);

        allPopup.setWidth(screenWidth);
        allPopup.setHeight(ViewGroup.LayoutParams.WRAP_CONTENT);
        allPopup.setFocusable(true);
        allPopup.setTouchable(true);
        allPopup.setOutsideTouchable(true);
        allPopup.setBackgroundDrawable(new ColorDrawable(0x00000000));

        allListView = (ListView) allView.findViewById(R.id.kind_listview);
        allAdapter = new AllReportApater(this, reportLists,reportId);
        allListView.setAdapter(allAdapter);
        allListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                for (int i = 0; i < reportLists.size(); i++) {
                    if (i == position) {
                        tv_title.setText(reportLists.get(i).getItemName() + "▼");
                        reportName = reportLists.get(i).getItemName();
                        reportId = reportLists.get(i).getItemId();
                    } else {

                    }
                }
                allAdapter.setData(reportLists,reportId);
                allPopup.dismiss();
                loading();
                YiJiaHuNetWorkUtils.getMyreportDetail(patientId, reportId, startDateStr, endDateStr, handler);

            }
        });
        allAdapter.setDisplayListener(new AllReportApater.DisplayListener() {
            @Override
            public void onDisplay(int position) {

            }
        });

        allWholeView = (View) allView.findViewById(R.id.kind_view_whole);
        allWholeView.setOnClickListener(this);

        allPopup.setOnDismissListener(new PopupWindow.OnDismissListener() {
            @Override
            public void onDismiss() {
//                BrightnessUtils.lightOn(getActivity());
                isTitleClick = false;
                tv_title.setText(reportName + "▼");
            }
        });
    }

    @Override
    protected void updateByHandler(Message msg) {
        switch (msg.what) {
            case MessageCode.NETWORKCODE_DELETEMYREPORT_SUCCESS:
                dismisssLoading();
                if (msg.obj != null) {
                    toastMsg(msg.obj.toString());
                    loading();
                    YiJiaHuNetWorkUtils.getMyreportDetail(patientId, reportId, startDateStr, endDateStr, handler);
                }
                break;
            case MessageCode.NETWORKCODE_DELETEMYREPORT_FAILURE:
                dismisssLoading();
                if (msg.obj != null) {
                    toastMsg(msg.obj.toString());
                    return;
                }

                break;

            case MessageCode.NETWORKCODE_MYREPORTDETAIL_SUCCESS:
                dismisssLoading();
                if (msg.obj != null) {
                    resultBean = (ObjectResultBean<MyReportValueBean>) msg.obj;
                    reportValueBeans.clear();
                    referenceTV.setText(getResources().getString(R.string.myreportdetail_text_reference) + resultBean.getData().getLowerValue() + "~" + resultBean.getData().getUpperValue() + resultBean.getData().getUnit());
                    dataUnitTV.setText(getResources().getString(R.string.reportinput_text_data) + resultBean.getData().getUnit());
                    unit = resultBean.getData().getUnit();
                    dataUnitTV.setVisibility(View.VISIBLE);
                    reportValueBeans = resultBean.getData().getList();
                    if (reportValueBeans != null && reportValueBeans.size() > 0) {
                        adapter.setReferMaxValue(resultBean.getData().getUpperValue());
                        adapter.setReferMinValue(resultBean.getData().getLowerValue());
                        adapter.setData(reportValueBeans);
                    }else{
                        adapter.setReferMaxValue(resultBean.getData().getUpperValue());
                        adapter.setReferMinValue(resultBean.getData().getLowerValue());
                        adapter.setData(reportValueBeans);
                    }
                    //渲染图表
                    try {
                        betweenDays = daysBetween(startDateStr, endDateStr);
                    } catch (ParseException e) {
                        e.printStackTrace();
                    }

                    double upper = 0;
                    if (!"".equals(resultBean.getData().getUpperValue())) {
                        upper = Double.parseDouble(resultBean.getData().getUpperValue());
                    }
                    double lower = 0;
                    if (!"".equals(resultBean.getData().getLowerValue())) {
                        lower = Double.parseDouble(resultBean.getData().getLowerValue());
                    }

                    if (!"".equals(resultBean.getData().getMaxValue())) {
                        max = Float.parseFloat(resultBean.getData().getMaxValue());
                    }

                    if (!"".equals(resultBean.getData().getMaxValue())) {
                        min = Float.parseFloat(resultBean.getData().getMinValue());
                    }
                    generateChartData(reportValueBeans, max, min, upper, lower);
                    chart.setLineChartData(data);
                    chart.setZoomEnabled(false);
                    chart.setScrollEnabled(true);

                    previewX(min, max);
                }

                break;
            case MessageCode.NETWORKCODE_MYREPORTDETAIL_FAILURE:
                dismisssLoading();
                if (msg.obj != null) {
                    toastMsg(msg.obj.toString());
                    return;
                }

                break;
        }
    }

    @Override
    protected void initView() {

        ll_title = (LinearLayout) findViewById(R.id.ll_title);
        iv_back = (ImageView) findViewById(R.id.iv_title_back);
        tv_title = (TextView) findViewById(R.id.tv_title_title);
        tv_input = (TextView) findViewById(R.id.tv_title_func);

        setTitlePadding(ll_title);
        iv_back.setVisibility(View.VISIBLE);
        iv_back.setOnClickListener(this);
        tv_input.setVisibility(View.VISIBLE);
        tv_input.setOnClickListener(this);
        tv_input.setText(getResources().getString(R.string.reportdetail_text_input));
        if (isDoctor) {
            tv_title.setText(reportName + "▼");
            tv_input.setVisibility(View.INVISIBLE);
            tv_title.setOnClickListener(this);
        } else {
            tv_title.setText(reportName);
        }

        startTV = (TextView) findViewById(R.id.reportdetail_tv_startdate);
        endTV = (TextView) findViewById(R.id.reportdetail_tv_enddate);
        allTV = (TextView) findViewById(R.id.reportdetail_tv_all);
        referenceTV = (TextView) findViewById(R.id.reportdetail_tv_reference);

        dataUnitTV = (TextView) findViewById(R.id.reportdetail_tv_dataunit);

        chart = (LineChartView) findViewById(R.id.reportdetail_chart);
//        // Generate data for previewed chart and copy of that data for preview chart.
//        generateDefaultData();
//
//        chart.setLineChartData(data);
//        //chart.getAxesRenderer().isMarin = true;
//        // Disable zoom/scroll for previewed chart, visible chart ranges depends on preview chart viewport so
//        // zoom/scroll is unnecessary.
//        chart.setZoomEnabled(false);
//        chart.setScrollEnabled(true);
//
//        previewX();


        recyclerView = (RecyclerView) findViewById(R.id.reportdetail_recyclerview);

        LinearLayoutManager mLayoutManager = new LinearLayoutManager(this);
        mLayoutManager.setOrientation(LinearLayoutManager.VERTICAL);
        recyclerView.setLayoutManager(mLayoutManager);

        adapter = new ReportDetailListAdapter(this, reportValueBeans, recyclerView, loginInfo.getUserStyle(), this);
        recyclerView.setAdapter(adapter);

        if (calendarView == null) {
            calendarView = new CalendarPopWindow(this);
        }
        calendarView.setCalendarListener(new CalendarPopWindow.CalendarListener() {
            @Override
            public void setCalendar(String calendar) {
                if (isStartDate) {
                    isStartDate = false;
                    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
                    long dateSelect = 0;
                    try {
                        dateSelect = sdf.parse(calendar).getTime();
                    } catch (ParseException e) {
                    }
                    long endDate = 0;
                    try {
                        endDate = sdf.parse(endDateStr).getTime();
                    } catch (ParseException e) {
                    }
                    if (dateSelect > endDate) {
                        toastMsg(R.string.reportdetail_text_wrongtime1);
                        return;
                    }
                    startDateStr = calendar;
                    startTV.setText(calendar);
                }
                if (isEndDate) {
                    isEndDate = false;
                    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
                    long dateSelect = 0;
                    try {
                        dateSelect = sdf.parse(calendar).getTime();
                    } catch (ParseException e) {
                    }
                    long startDate = 0;
                    try {
                        startDate = sdf.parse(startDateStr).getTime();
                    } catch (ParseException e) {
                    }
                    if (startDate > dateSelect) {
                        toastMsg(R.string.reportdetail_text_wrongtime2);
                        return;
                    }
                    endDateStr = calendar;
                    endTV.setText(calendar);
                }
                loading();
                YiJiaHuNetWorkUtils.getMyreportDetail(patientId, reportId, startDateStr, endDateStr, handler);


            }
        });

        Calendar cal = Calendar.getInstance();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        endDateStr = sdf.format(cal.getTime());
        endTV.setText(endDateStr);


        Calendar c = Calendar.getInstance();
        c.add(Calendar.DATE, -7);
        Date weekDate = c.getTime();
        startDateStr = sdf.format(weekDate);
        startTV.setText(startDateStr);

        initAllPopup();
    }

    @Override
    protected void initListener() {
        startTV.setOnClickListener(this);
        endTV.setOnClickListener(this);
        allTV.setOnClickListener(this);
    }

    @Override
    protected void initData() {

        loading();
        YiJiaHuNetWorkUtils.getMyreportDetail(patientId, reportId, startDateStr, endDateStr, handler);

    }

    @Override
    public void onResume() {
        super.onResume();
        initData();
    }

    private void generateChartData(List<ReportValueBean> beans, double maxV, double minV, double upperValue, double lowerValue) {
        if (beans != null && beans.size() != 0) {//图表有数据点
            List<PointValue> values = new ArrayList<PointValue>();
            for (int i = 0; i < beans.size(); ++i) {
                double value = Double.parseDouble(beans.get(i).getValue());
                SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                long timeStamp = Long.parseLong(Utils.date2TimeStamp(beans.get(i).getTime(), "yyyy-MM-dd HH:mm:ss"));
                String pointTime = beans.get(i).getTime();
//                String currentTime = format.format(new java.util.Date());
                int days = 0;
                try {
                    days = daysBetween(pointTime, endDateStr);
                } catch (ParseException e) {
                    e.printStackTrace();
                }
                Date d1 = new Date(timeStamp);
                int timepoint = ((betweenDays - days) * 24) + d1.getHours();
                System.out.println("timepoint====" + timepoint);
                System.out.println("betweenDays====" + betweenDays);
                PointValue point = new PointValue(timepoint, (float) value);
                Resources res = mContext.getResources();
                point.setColor("3");//淡蓝色
                point.setPurpliColor(mContext.getResources().getColor(R.color.light_blue));

                if (value > lowerValue && value < upperValue) {

                } else if (value > upperValue) {
                    point.setBig(true);
                } else if (value < lowerValue) {
                    point.setBig(true);
                }
                values.add(point);
            }

            Line line = new Line(values);
            line.setColor(mContext.getResources().getColor(R.color.light_blue));
            List<Line> lines = new ArrayList<Line>();
            lines.add(line);

            data = new LineChartData(lines);

            List<AxisValue> mAxisValues = new ArrayList<AxisValue>();
            for (int i = 0; i < (betweenDays + 1) * 24; i++) {
                String newDate = "";
                if (betweenDays == 2) {
                    newDate = getDateAdd(betweenDays - (i / 20));
                    mAxisValues.add(new AxisValue(i).setLabel(newDate.split("-")[1] + "-" + newDate.split("-")[2]));
                } else if (betweenDays == 1) {
                    newDate = getDateAdd(betweenDays - (i / 24));
                    String date = newDate.split("-")[1] + "-" + newDate.split("-")[2];
                    if (i == 0) {
                        mAxisValues.add(new AxisValue(i).setLabel(newDate.split("-")[1] + "-" + newDate.split("-")[2]));
                    } else if (i > 24 && i < 36) {
                        mAxisValues.add(new AxisValue(i).setLabel(newDate.split("-")[1] + "-" + newDate.split("-")[2]));
                    } else {
                        mAxisValues.add(new AxisValue(i).setLabel(""));
                    }
                } else if (betweenDays == 0) {
                    newDate = getDateAdd(betweenDays - (i / 24));
                    if (i == 0) {
                        mAxisValues.add(new AxisValue(i).setLabel(newDate.split("-")[1] + "-" + newDate.split("-")[2]));
                    } else {
                        mAxisValues.add(new AxisValue(i).setLabel(""));
                    }
                } else {
                    newDate = getDateAdd(betweenDays - (i / 24));
                    mAxisValues.add(new AxisValue(i).setLabel(newDate.split("-")[1] + "-" + newDate.split("-")[2]));
                }
//                System.out.println("newDate====" + newDate + "i====" + i);
            }


            Axis axisX = new Axis(mAxisValues);
            data.setAxisXBottom(axisX);

            List<AxisValue> yAxisValues = new ArrayList<AxisValue>();
            int maxInt = (int) maxV;
            int minInt = (int) minV;
            int interValue = (int) Math.ceil(((double) (maxInt - minInt) / 5));
            yAxisValues.add(new AxisValue(0).setLabel(0 + "")); //为每个对应的i设置相应的label(显示在Y轴)
            yAxisValues.add(new AxisValue(interValue).setLabel(interValue + "")); //为每个对应的i设置相应的label(显示在Y轴)
            yAxisValues.add(new AxisValue(interValue * 2).setLabel((interValue * 2) + ""));
            yAxisValues.add(new AxisValue(interValue * 3).setLabel((interValue * 3) + ""));
            yAxisValues.add(new AxisValue(interValue * 4).setLabel((interValue * 4) + ""));
            yAxisValues.add(new AxisValue(interValue * 5).setLabel((interValue * 5) + ""));

            Axis axisY = new Axis(yAxisValues).setHasLines(true);
            data.setAxisYLeft(axisY);

        } else {//图表无数据点
            List<PointValue> values = new ArrayList<PointValue>();
            Line line = new Line(values);
            line.setColor(mContext.getResources().getColor(R.color.light_blue));
            List<Line> lines = new ArrayList<Line>();
            lines.add(line);
            data = new LineChartData(lines);

            List<AxisValue> mAxisValues = new ArrayList<AxisValue>();
            for (int i = 0; i < (betweenDays + 1) * 24; i++) {
                String newDate = "";
                if (betweenDays == 2) {
                    newDate = getDateAdd(betweenDays - (i / 20));
                    mAxisValues.add(new AxisValue(i).setLabel(newDate.split("-")[1] + "-" + newDate.split("-")[2]));
                } else if (betweenDays == 1) {
                    newDate = getDateAdd(betweenDays - (i / 24));
                    String date = newDate.split("-")[1] + "-" + newDate.split("-")[2];
                    if (i == 0) {
                        mAxisValues.add(new AxisValue(i).setLabel(newDate.split("-")[1] + "-" + newDate.split("-")[2]));
                    } else if (i > 24 && i < 36) {
                        mAxisValues.add(new AxisValue(i).setLabel(newDate.split("-")[1] + "-" + newDate.split("-")[2]));
                    } else {
                        mAxisValues.add(new AxisValue(i).setLabel(""));
                    }
                } else if (betweenDays == 0) {
                    newDate = getDateAdd(betweenDays - (i / 24));
                    if (i == 0) {
                        mAxisValues.add(new AxisValue(i).setLabel(newDate.split("-")[1] + "-" + newDate.split("-")[2]));
                    } else {
                        mAxisValues.add(new AxisValue(i).setLabel(""));
                    }
                } else {
                    newDate = getDateAdd(betweenDays - (i / 24));
                    mAxisValues.add(new AxisValue(i).setLabel(newDate.split("-")[1] + "-" + newDate.split("-")[2]));
                }
//                System.out.println("newDate====" + newDate + "i====" + i);
            }


            Axis axisX = new Axis(mAxisValues);
            data.setAxisXBottom(axisX);

            List<AxisValue> yAxisValues = new ArrayList<AxisValue>();
            int maxInt = (int) maxV;
            int minInt = (int) minV;
            int interValue = (int) Math.ceil(((double) (maxInt - minInt) / 5));
            yAxisValues.add(new AxisValue(0).setLabel(0 + "")); //为每个对应的i设置相应的label(显示在Y轴)
            yAxisValues.add(new AxisValue(interValue).setLabel(interValue + "")); //为每个对应的i设置相应的label(显示在Y轴)
            yAxisValues.add(new AxisValue(interValue * 2).setLabel((interValue * 2) + ""));
            yAxisValues.add(new AxisValue(interValue * 3).setLabel((interValue * 3) + ""));
            yAxisValues.add(new AxisValue(interValue * 4).setLabel((interValue * 4) + ""));
            yAxisValues.add(new AxisValue(interValue * 5).setLabel((interValue * 5) + ""));

            Axis axisY = new Axis(yAxisValues).setHasLines(true);
            data.setAxisYLeft(axisY);
        }
    }

    public String getDateAdd(int m) {
//        Date date = new Date();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
//        String now = sdf.format(date);
//        long l = date.getTime() - (long) 24 * 60 * 60 * m * 1000;
        long l = Long.parseLong(Utils.date2TimeStamp(endDateStr, "yyyy-MM-dd")) - (long) 24 * 60 * 60 * m * 1000;
        String newd = sdf.format(new Date(l));
        return newd;
    }

    public static int daysBetween(String smdate, String bdate) throws ParseException {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        Calendar cal = Calendar.getInstance();
        cal.setTime(sdf.parse(smdate));
        long time1 = cal.getTimeInMillis();
        cal.setTime(sdf.parse(bdate));
        long time2 = cal.getTimeInMillis();
        long between_days = (time2 - time1) / (1000 * 3600 * 24);

        return Integer.parseInt(String.valueOf(between_days));
    }


    private void previewX(float minV, float maxV) {
        Viewport maxViewport = new Viewport();
        maxViewport.bottom = 0;
        maxViewport.top = maxV;
        maxViewport.left = 0;
        if (betweenDays < 3) {
            maxViewport.right = (betweenDays + 1) * 24;
        } else {
            maxViewport.right = (betweenDays + 2) * 24;
        }

        chart.setMaximumViewport(maxViewport);

        Viewport tempViewport = new Viewport(chart.getMaximumViewport());
        float dx = tempViewport.width();
        tempViewport.inset(dx, 0);
        tempViewport.offsetTo(0, maxV);
        chart.setCurrentViewport(tempViewport);
        chart.setZoomType(ZoomType.HORIZONTAL);
    }


    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.kind_view_whole:
                allPopup.dismiss();
                break;
            case R.id.tv_title_title:
                if(isTitleClick){
                    if(allPopup != null){
                        allPopup.dismiss();
                    }
                    isTitleClick = false;
                }else{
                    tv_title.setText(reportName+"▲");
                    allPopup.showAsDropDown(ll_title);
                    isTitleClick = true;
                }

                break;
            case R.id.iv_title_back:
                finish();
                break;
            case R.id.tv_title_func:
                //录入
                Intent intent = new Intent(this, MyReportInputActivity.class);
                intent.putExtra("reportId", reportId);
                intent.putExtra("reportName", reportName);
                intent.putExtra("max", max);
                intent.putExtra("min", min);
                intent.putExtra("unit", unit);
                startActivity(intent);
                break;
            case R.id.reportdetail_tv_startdate:
                //开始日期
                isStartDate = true;
                calendarView.showBottom(ll_title);
                break;
            case R.id.reportdetail_tv_enddate:
                //结束日期
                isEndDate = true;
                calendarView.showBottom(ll_title);
                break;
            case R.id.reportdetail_tv_all:
                //全部
                Intent allIntent = new Intent(this, MyAllReportListActivity.class);
                allIntent.putExtra("reportId", reportId);
                allIntent.putExtra("patientid", patientId);
                allIntent.putExtra("reportName", reportName);
                allIntent.putExtra("startDate", startDateStr);
                allIntent.putExtra("endDate", endDateStr);
                allIntent.putExtra("unit",unit);
                startActivity(allIntent);
                break;
        }
    }

    @Override
    public void PostOptions(View view, int position, String optionType) {
        if ("delete".equals(optionType)) {//删除操作
            loading();
            YiJiaHuNetWorkUtils.deleteMyReport(reportValueBeans.get(position).getValueId(), handler);
        } else if ("edit".equals(optionType)) {//编辑界面
            Intent intent = new Intent(mContext, MyReportInputActivity.class);
            intent.putExtra("reportId", reportId);
            intent.putExtra("reportName", reportName);
            intent.putExtra("time", reportValueBeans.get(position).getTime());
            intent.putExtra("data", reportValueBeans.get(position).getValue());
            intent.putExtra("valueid", reportValueBeans.get(position).getValueId());
            intent.putExtra("picPath", reportValueBeans.get(position).getPic());
            intent.putExtra("max", max);
            intent.putExtra("min", min);
            intent.putExtra("unit", unit);
            mContext.startActivity(intent);
        } else if ("displayImg".equals(optionType)) {
            Intent iPhotos = new Intent(mContext, DisplayImageActivity.class);
            iPhotos.putExtra("path", reportValueBeans.get(position).getPic());
            iPhotos.putExtra("isHideDelete", "true");
            iPhotos.putExtra("position", position);
            List<String>  picList=new ArrayList<>();
            for (int i = 0; i < reportValueBeans.size(); i++) {
                picList.add(reportValueBeans.get(i).getPic());
            }
            iPhotos.putStringArrayListExtra("pics", (ArrayList<String>) picList);
            startActivity(iPhotos);
        }
    }
}
